<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>比赛成绩列表</title>
    <script src="../../res/js/jquery-3.4.1.min.js"></script>
    <script src="../../res/layui/layui.js"></script>
    <script src="../../res/js/Tools.js"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css">
    <script src="../../res/js/base.js"></script>


</head>
<body>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">批量删除</button>
        <button class="layui-btn layui-btn-sm" lay-event="addBtn">新增</button>

    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>



<table id="demo" lay-filter="test"></table>


<script>
var table2 = null ;
var table=null;

layui.use('table', function(){
table = layui.table
,form = layui.form;

//第一个实例

    var table2 = null;
    var form = null;
    layui.use(['table','form'], function() {
        var table = layui.table;

        form = layui.form;

        //第一个实例
        table2 = table.render({
            elem : '#demo',
            height : 550,
            toolbar : '#toolbarDemo',

            url: getRootPath() + 'atsDataDicController/selectAll',
            page : true //开启分页
            ,
            cols : [ [ //表头
                {
                    type : 'checkbox',
                    fixed : 'left'
                }, {
                    field : 'did',
                    title : '字典ID',
                    width : 150
                }, {
                    field : 'dcode',
                    title : '字典编码',
                    width : 200
                }, {
                    field : 'dname',
                    title : '字典名称',
                    width : 200
                },{
                    field : 'dtype',
                    title : '字典类型',
                    width : 200
                }, {
                    field : 'action',
                    title : '操作',
                    width : 120,
                    toolbar : "#barDemo"
                } ] ]

        });



        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':

                    layer.confirm('您真的要删除吗?', function(index){
                        var data = checkStatus.data;
                        var ids="";

                        $.each(data,function(index,item){
                            ids+=item.did+",";
                        })

                        var url=getRootPath()+'atsDataDicController/deleteAll';
                        var dates={ids:ids};
                        $.post(url,dates,function(obj){
                            layer.msg(obj.msg);
                            table2.reload();

                        },"json")

                    });

                    break;

                case 'addBtn':
                    //iframe层

                    layer.open({
                        type: 2,
                        title: 'xxxxx',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['50%', '92%'],
                        content: 'AtsDataDicFrom.html', //iframe的url
                        end : function() {
                            table2.reload();
                        }
                    });
                    break;
            };
        });

        table.on('tool(test)', function(obj){
            var data = obj.data;//行数据
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('您真的要删除吗?', function(index){
                    obj.del();
                    layer.close(index);

                    var url=getRootPath()+'atsDataDicController/deleteByPrimaryKey';
                    var date={did:data.did};
                    $.post(url,date,function(obj){
                        layer.msg(obj.msg)
                    },"json")






                });
            } else if(obj.event === 'edit'){

                var data = obj.data;//行数据

                //iframe层
                layer.open({
                    type: 2,
                    title: '会员资料维护页面',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['47%', '92%'],
                    content: 'page/back/tgls/Membership/MembershipForm.jsp?id='+data.vipId, //iframe的url
                    end : function() {
                        table2.reload();
                    }
                });
            }
        });

    });
});

</script>

</body>

</body>
</html>